<?php
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\bootstrap\modal;
use yii\helpers\html;
//var_dump($dataProvider);
$gridColumns = [
    [
        'format' => 'html',
        'attribute' => 'user_name',
        'label'=>'Image',
        'headerOptions' => ['width' => '80%',],
    ],

    [   'class' => 'yii\grid\ActionColumn',
        // 'header' => '操作',
        'template' => '{user-view}',
            'buttons' => [
                // 下面代码来自于 yii\grid\ActionColumn 简单修改了下
                'user-view' => function ($url, $model, $key) {
                  $options = [
                  'title' => '查看',
                  'aria-label' => '查看',
                  'data-pjax' => '0',
                  'class' => 'btn btn-info btn-xs',
                  'icon' => 'eye-open',
              ];
                    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                },
        // 'buttons' => [
            // 'view' => function ($url, $model, $key) {
                // return Html::a('<span class="glyphicon glyphicon-refresh"></span>', $url, [
                //     'id' => 'activity-view-link',
                //     'title' => Yii::t('yii', 'Viewllllll'),
                //     'data-toggle' => 'modal',
                //     'data-target' => '#activity-modal',
                //     'data-id' => $key,
                //     'data-pjax' => '0',
                //
                // ]);
            //     $options = [
            //         'title' => Yii::t('yii', 'View'),
            //         'aria-label' => Yii::t('yii', 'View'),
            //         'data-pjax' => '0',
            //         'data-id' => $key,
            //     ];
            //     return Html::a('<span class="glyphicon glyphicon-refresh"></span>', $url, $options);
            // },
        ],


    ],

];
?>


<?php

Pjax::begin();

echo GridView::widget([
    'dataProvider' => $dataProvider,
    'columns'=>$gridColumns,
    'summary'=>false,
    // 'responsive'=>true,
    // 'hover'=>true
]);
Pjax::end();

?>


<?php $this->registerJs(
    "$('.activity-view-link').click(function() {
    $.get(
        'index.php?r=post/recomment',
        {
            id: $(this).closest('tr').data('key')
        },
        function (data) {
            $('.modal-body').html(data);
            $('#activity-modal').modal();
        },'json'
    );
});
    "
); ?>

<?php


?>

<?php Modal::begin([
    'id' => 'activity-modal',
    'header' => '<h4 class="modal-title">View Image</h4>',
    'footer' => '<a href="#" class="btn btn-primary" data-dismiss="modal">Close</a>',

]); ?>

<div class="well">


</div>


<?php Modal::end(); ?>
